package com.goddess.yeecolor.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.andview.refreshview.recyclerview.BaseRecyclerAdapter;
import com.goddess.yeecolor.Modle.ActivityFragmentModle;
import com.goddess.yeecolor.R;
import com.goddess.yeecolor.tools.ImageUtils;

import java.util.List;

/**
 * 作者: CaoJunping
 * 时间: 2017/1/16
 * 作用: ******
 * 备注: 我的Framgnet个人收藏Activity视频Fragment
*/
public class VideoFragmentAdapter extends BaseRecyclerAdapter<VideoFragmentAdapter.VideoAdapterViewHolder> {
    private Context context;

    private List<ActivityFragmentModle> list;

    public VideoFragmentAdapter(Context context, List<ActivityFragmentModle> list) {
        this.context = context;
        this.list = list;
    }
    @Override
    public VideoAdapterViewHolder getViewHolder(View view) {
        return new VideoAdapterViewHolder(view);
    }

    @Override
    public VideoAdapterViewHolder onCreateViewHolder(ViewGroup parent, int viewType, boolean isItem) {
        View view= LayoutInflater.from(context).inflate(R.layout.video_fragment_recycler_item,parent,false);
        return new VideoAdapterViewHolder(view);
    }

    @Override
    public void onBindViewHolder(VideoAdapterViewHolder holder, int position, boolean isItem) {
        ActivityFragmentModle modle=list.get(position);
        holder.title.setText(modle.getTitle());
//        holder.state.setText(modle.);
        holder.date.setText(modle.getAddtime());
        ImageUtils.getInstance().ImageStart(context,modle.getThumb(),holder.img);
        holder.img.setScaleType(ImageView.ScaleType.FIT_XY);
    }

    @Override
    public int getAdapterItemCount() {
        return list.size();
    }

    class VideoAdapterViewHolder extends RecyclerView.ViewHolder{
        private ImageView img;
        private TextView title,state,date;
        public VideoAdapterViewHolder(View itemView) {
            super(itemView);
            img = (ImageView) itemView.findViewById(R.id.img);
            title= (TextView) itemView.findViewById(R.id.tv_title);
            state= (TextView) itemView.findViewById(R.id.tv_state);
            date= (TextView) itemView.findViewById(R.id.tv_date);


            /**
             * 点击事件
             */
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                     onItemClicklistener.OnItemClick(itemView,getLayoutPosition()-1);
                }
            });

        }
    }

    /**
     * 每一行的点击事件接口
     */
    public interface  OnItemClicklistener{
        void OnItemClick(View view, int position);
    }
    private OnItemClicklistener onItemClicklistener;
    public void setOnItemClicklistener(OnItemClicklistener onItemClicklistener){
        this.onItemClicklistener=onItemClicklistener;
    }


    /**
     * 清空适配器
     */
    public void clear(){
        clear(list);
    }


    /**
     * 刷新增加数据
     */
    public void insert(ActivityFragmentModle modle,int position){
        insert(list,modle,position);
    }
}
